package com.zhuchaooasystem.ui.home.fragment.message;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.zhuchaooasystem.R;
import com.zhuchaooasystem.adapter.MessageVPAdapter;
import com.zhuchaooasystem.base.BaseActivity;
import com.zhuchaooasystem.presenter.home.fragment.message.MessageReadContract;
import com.zhuchaooasystem.presenter.home.fragment.message.MessageReadPresenter;
import com.zhuchaooasystem.widget.ViewpagerNoScroll;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author yinsi
 */

public class MessageReadActivity extends BaseActivity<MessageReadPresenter> implements MessageReadContract.View {

    @BindView(R.id.actionbar_iv_back)
    ImageView iv_back;
    @BindView(R.id.actionbar_txt_title)
    TextView txt_title;
    //----
    @BindView(R.id.fragment_message_vp)
    ViewpagerNoScroll fragmentMessageVp;
    @BindView(R.id.fragment_message_tab)
    TabLayout fragmentMessageTab;

    private List<Fragment> fragments;
    private List<String> titleList;

    private MessageVPAdapter adapter;

    @Override
    protected int getLayout() {
        return R.layout.activity_message_read;
    }

    @Override
    protected MessageReadPresenter getPresenter() {
        return new MessageReadPresenter(mContext, this);
    }

    @Override
    protected void initVariables() {

    }

    @Override
    protected void initView() {
        setActionBar();
        //----
        fragments = new ArrayList<>();
        titleList = new ArrayList<>();

        fragments.add(new ServiceMessageReadFragment());
        fragments.add(new InformMessageReadFragment());

        titleList.add("服务消息");
        titleList.add("通知消息");

        adapter = new MessageVPAdapter(getSupportFragmentManager(), titleList, fragments);

        fragmentMessageTab.setupWithViewPager(fragmentMessageVp);
        fragmentMessageVp.setAdapter(adapter);
    }

    private void setActionBar() {
        iv_back.setVisibility(View.VISIBLE);
        txt_title.setText(getString(R.string.actionbar_title_message_read));
        txt_title.setVisibility(View.VISIBLE);
    }

    @Override
    protected void initDataAndLoadData() {

    }

    @OnClick(value = {R.id.actionbar_iv_back, R.id.actionbar_iv_right})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.actionbar_iv_back:
                finish();
                break;
        }
    }

    public void changeTitle(String type, int size) {
        if (type.equals("service")) {
            titleList.set(0, "服务消息 " + size);
        } else if (type.equals("inform")) {
            titleList.set(1, "通知消息 " + size);
        }
        adapter.changeTitle(titleList);
    }


}
